package com.devshephard.jucks.countDown.countDownLunch;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class countDownLunchTest {

    public static void main(String[] args) throws InterruptedException {

        //定义一个线程减法计数器，计数数量为6
        CountDownLatch countDownLatch = new CountDownLatch(3);

        for (int i = 0; i < 3; i++) {
            //循环开启线程
            new Thread(()->{
                System.out.println(Thread.currentThread().getName() + " Go");
                //每开启一个线程，计算减一（切记，这个计算是写在线程的方法体里面的）
                countDownLatch.countDown();
            },String.valueOf(i)).start();

        }

        //当所有线程执行完毕后，在走下一步
        countDownLatch.await(5, TimeUnit.SECONDS);
        //countDownLatch.await();

        System.out.println("线程执行完毕，当前数量：" + countDownLatch.getCount());

    }

}
